package com.yizhu.zczy.system.interceptor;

import com.yizhu.zczy.system.constant.SystemConstant;
import com.yizhu.zczy.system.entity.UserEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class MyHandlerInterceptor  implements HandlerInterceptor {
    public static ThreadLocal<UserEntity> threadLocal=new ThreadLocal<>();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        UserEntity attribute = (UserEntity) session.getAttribute(SystemConstant.USER_SESSION_SAVE);
        if (attribute ==null){
            return false;
        }
        threadLocal.set(attribute);
        return true;

    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

}
